﻿using System;
using System.Collections.Generic;
using ExcelDataReader;

namespace ExcelToApi
{
    public class Util
    {
        public static FileSystemInfo[] GetAllFileByPath(string pPath)
        {
            if (Directory.Exists(pPath))
            {
                DirectoryInfo directory = new DirectoryInfo(pPath);
                FileSystemInfo[] filesArray = directory.GetFileSystemInfos();
                return filesArray;
            }
            else
            {
                return null;
            }
        }

        public static void DeleteAllFilesByPath(string pPath)
        {
            if (Directory.Exists(pPath))
            {
                DirectoryInfo directory = new DirectoryInfo(pPath);
                FileSystemInfo[] filesArray = directory.GetFileSystemInfos();
                foreach (FileSystemInfo fileSystemInfo in filesArray)
                {
                    File.Delete(fileSystemInfo.FullName);
                }
            }
        }

        public static bool FileIsOpen(string pConfigPath)
        {
            try
            {
                File.OpenRead(pConfigPath);
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
